﻿						<div class="box border green">
									<div class="box-title">
										<h4><i class="fa fa-table"></i>新闻列表</h4>
										<div class="tools hidden-xs">
											<a href="#box-config" data-toggle="modal" class="config">
												<i class="fa fa-cog"></i>
											</a>
											<a href="javascript:;" class="reload">
												<i class="fa fa-refresh"></i>
											</a>
											<a href="javascript:;" class="collapse">
												<i class="fa fa-chevron-up"></i>
											</a>
											<a href="javascript:;" class="remove">
												<i class="fa fa-times"></i>
											</a>
										</div>
									</div>
									<div class="box-body">
										<form action="index.php?c=news&a=del&admin=1" method="post" >

										<table id="" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th class="width-1 center" width="80" >
														全选
														<div class="checker" style="float:right;margin-right:4px;"><span><input type="checkbox" name="all"></span></div>

													</th>
													<th >#</th>
													<th>新闻标题</th>
													<th>图片</th>
													<th>内容</th>
													<th class="hidden-xs">类型</th>
													<th>作者</th>
													<th class="hidden-xs">发布者</th>
													<th>日期</th>
													<th>状态</th>
													<th>操作</th>

												</tr>
											</thead>
											<tbody>
												<?php
													if(!empty($date)){
													foreach($date as $v){?>
													<tr class="gradeX">
														<td class="center">
															<div class="checker" style="float:right;margin-right:4px;"><span><input type="checkbox" class="ckbox" name="checked[]" value="<?php echo $v['id']?>"></span></div>
														</td>
														<td id="id"><?php echo $v['id']?></td>
														<td class="exdit" co="<?php echo 'title'?>"><?php echo mb_substr($v['title'],0,10,'utf-8').'...'?></td>
														<td class="center "><img width="80px" height="60px" src="<?php echo (empty($v['url']))?'./det.png':$v['url']?>" ></td>
														<td class="exdit" co="<?php echo 'content'?>"><?php echo mb_substr($v['content'],0,30,'utf-8').'...'?></td>
														<td class="hidden-xs edit" co="<?php echo 'type'?>" ><?php echo $v['name']?></td>
														<td class="center "><?php echo $v['author']?></td>
														<td class="center hidden-xs"><?php echo $v['sendter']?></td>
														<td class="center hidden-xs"><?php echo $v['creat_time']?></td>
														<td class="center status hidden-xs"><?php  echo ($v['statius']==0)?"<a class='btn btn-pink do' status='0'><i class='fa fa-times'></i></a>":"<a class='btn btn-success do' status='1'><i class='fa fa-check'></i></a>" ?></td>
														<td class="center hidden-xs" style="width:160px">
															<a href="index.php?c=news&a=edit&admin=1&id=<?php echo $v['id']?>" class="btn btn-info"><i class="fa fa-pencil-square-o"></i>编辑</a>
															<a class="btn btn-danger" href="index.php?c=news&a=del&id=<?php echo $v['id']?>" onclick="return confirm('确定要删除吗');"><i class="fa fa-trash-o"></i>删除</a>
														</td>
													</tr>
												<?php }}?>
											</tbody>

										</table>
										<button class='btn btn-success' id="ajs" type="button" g="0"><i  class='fa fa-check' >批量审批</i></button>
										<button class='btn btn-danger' type="submit" onclick="return confirm('确定要删除吗');"><i  class='fa fa-trash-o' id="del">批量删除</i></button>

										<button id="add" style="float:right;margin-right:50px;" class='btn btn-success' type="button"><i class='fa fa-pencil-square-o' >前增一行</i></button>

										</form>
										<div class="row">
											<div class="col-sm-12">
												<div class="pull-left">
													<div class="dataTables_info" id="datatable1_info">Showing 1 to 9 of 9 entries</div>
												</div>
												<div class="pull-right">
												    <div class="dataTables_paginate paging_bs_full" id="datatable1_paginate">
												   		<ul class="pagination">
															<?=$page_str?>
									   					</ul>
								   					</div>
												</div>
												<div class="clearfix"></div>
											</div>
										</div>
									</div>
								</div>

<script src="resources/admin/js/jquery/jquery-2.0.3.min.js"></script>
<script type="text/javascript">

/*点击增加一行*/
			$('form').on('click','#add',function(){
				var rows = '';
				rows+='<tr class="gradeX">';
				rows+='<td class="center">';
				rows+='<div class="checker" style="float:right;margin-right:4px;"><span><input type="checkbox" class="ckbox" name="checked[]" value=""></span></div>';
				rows+="</td>";
				rows+="<td id='id'></td>";
				rows+="<td class='exdit' co='addtitle'></td>";
				rows+="<td class='center'><img src=''></td>";
				rows+="<td class='exdit' co='addcontent'></td>";
				rows+="<td class='hidden-xs exdit' co='addtype' ></td>";
				rows+="<td class='center'></td>";
				rows+="<td class='center hidden-xs'></td>";
				rows+="<td class='center hidden-xs'></td>";
				rows+="<td class='center status hidden-xs'> <a class='btn btn-pink do' status='0'><i class='fa fa-times'></i></a></td>";
				rows+="<td class='center hidden-xs' style='width:160px'>";
				rows+="<a class='btn btn-light-grey save' href='index.php?c=news&a=list&admin=1'><i class='fa fa-pencil-square-o'></i>保存</a>";
				rows+="<button type='button' class='btn btn-light-grey cancle'><i class='fa fa-trash-o'></i>取消</button></td></tr>";

				/*在tbody下找到第一个tr在它之前添加标签*/
				$('tbody').find('tr').first().before(rows);

				/*抓取保存按钮*/
				$('.save').click(function(){

					var rand = Math.random(0,5);

					$.ajax({
						url: 'index.php?c=news&a=list&admin=1&ss='+rand,
						type: 'get',
						data: {
							'title':$("td[co=addtitle]").text(),
							'content':$("td[co=addcontent]").text(),
							'type':$("td[co=addtype]").text()
						}
					})


				})
				/*抓取 取消按钮删除增加的一行*/
				$('.cancle').click(function(){
					$('tbody').find('tr').first().remove();
				})

			})
/*/点击增加一行*/

/*批量选中删除功能*/
	$(function(){
	/*点击全选时，所有子选项选中*/
	$('input[name=all]').click(function(){

		//所有子选项选中 this.checked是当前操作标签的checked属性
		$('.ckbox').prop("checked",this.checked);



	})
		//点击子选项时
		$('.row').on('click','.ckbox',function(){

		//当所有子选项的长度等于选中状态的子选项长度时，给全选，选中
		if($('.ckbox').length==$('.ckbox:checked').length){
			$('input[name=all]').prop('checked',this.checked);

		}
		if($('.ckbox').length!=$('.ckbox:checked').length){
			$('input[name=all]').prop('checked',false);

		}
		//$('pagination').on('click','.fly',function(){$('input[name=all]').prop('checked',false);})
	})

	//       if($(this).prop('checked')==true){

		//  $('.ckbox').prop("checked",true);
	//       }else{
		// $('.ckbox').prop("checked",false);
	//       }
	//
/*/批量选中删除功能*/

/*批量审核功能*/
	$('form').on('click','#ajs',function(){

		/*判断是否有勾选数据*/

		/*获取勾选的checkbox长度*/
		var len=$('.ckbox:checked').length;
		if(len>0){

					/*勾选框个数>0则获取已勾选的数据的id和它的status值并存入数组中.prop('status')*/
					var date= new Array();
					var data= new Array();

					/*获取已勾选数据的id存入数组中*/
					$('.ckbox:checked').each(function(i){
						//var de = $(this).parents('tr').eq(0).find('td.status a').attr('status');
						// alert(de);
						date[i]=this.value;

					})

					/*获取当前已勾选数据的status值*/
						// var leng = $('.ckbox:checked').parents('tr').find('td.status a').length;
						// alert(leng);
					 	$('.ckbox:checked').parents('tr').find('td.status a').each(function(i){

					 		data[i]=$(this).parents('tr').find('td.status a').attr('status');
					 	})

					 	/*这里抓到的是所有含有status类的td 下的a标签*/
					 	var obj = $('.ckbox:checked').parents('tr').find('td.status a');

					// $('.ckbox:checked').parent().parent().parent().find('.do').attr('status').each(function(i){

					// 	data[i]=this.value;
					// })

					$.ajax({
							url: 'index.php?c=news&a=del&admin=1',
							type: 'GET',
							data:{'eid':date,'status':data},
							dataType:'json',
							success:function(json){
								//将返回的数组进行循环

								for(i in json){

									if(json[i]==1){

										// but.attr('g',1);

										/*修改a标签的属性名为status的值为1*/

										/*obj.eq(i) 选取找到的以i为下标的a标签*/


										obj.eq(i).attr('status','1');

										/*删除a对象的btn-pink类*/
										obj.eq(i).removeClass('btn-pink');

										/*添加btn-success类*/
										obj.eq(i).addClass('btn-success');

										/*在当前标签下再找到i标签，移除fa-times类*/
										obj.eq(i).find('i').removeClass('fa-times');

										/*在当前标签下再找到i标签，添加fa-check类*/
										obj.eq(i).find('i').addClass('fa-check');
									}else{


										/*修改a标签的属性名为status的值为1*/
										obj.eq(i).attr('status','0');

										/*删除a对象的btn-success类*/
										obj.eq(i).removeClass('btn-success');

										/*添加btn-pink类*/
										obj.eq(i).addClass('btn-pink');

										/*在当前标签下再找到i标签，移除fa-check类*/
										obj.eq(i).find('i').removeClass('fa-check');

										/*在当前标签下再找到i标签，添加fa-times类*/
										obj.eq(i).find('i').addClass('fa-times');
									}
								}

							}

						})

				}else{
					alert("您没有勾选数据");
				}

	})
/*批量审核功能*/

/*点击改变审核状态功能*/
		$('tbody').on('click','.do',function(){

			/*获取当前标签的id*/
			var id = $(this).parent().parent().find('#id').text();

			/*获取当前数据的status值*/
			var stu = $(this).attr('status');

			var tis =$(this);

			$.ajax({
				type:'get',
				url:'index.php?c=news&a=list&admin=1&id='+id+'&s='+stu,
				success:function(json){

					if(json>=0){

						//判断如果当前操作标签是类为btn-pink的标签
						if(tis.is('.btn-pink')){

							/*修改当前标签的属性名为status的值为1*/
							tis.attr('status','1');

							/*则删除当前对象的btn-pink类*/
							tis.removeClass('btn-pink');

							/*添加btn-success类*/
							tis.addClass('btn-success');

							/*在当前标签下再找到i标签，移除fa-times类*/
							tis.find('i').removeClass('fa-times');

							/*在当前标签下再找到i标签，添加fa-check类*/
							tis.find('i').addClass('fa-check');


						}else{
							tis.removeClass('btn-success');

							tis.addClass('btn-pink');
							tis.find('i').removeClass('fa-check');

							tis.find('i').addClass('fa-times');
							tis.attr('status','0');
						}



					}

				}
			})
		})
/*/点击改变审核状态功能*/


$('tbody').on('dblclick','.edit',function(){
		var list = '';

		list+='<select class="form-control slec " name="pid" >';
		list+='<option value="">上一级</option>';
		list+='<option value="">漫画</option>';
		list+='<option value="">动漫</option>';


		list+='<option value=""></option>';


		list+='</select>';


		$('.edit').html(list);
})

$('tbody').on('change','select',function(){

	//获取选中的文本
	var va = $(this).find('option:selected').text();

	$('.edit').text(va);
})

})

</script>